<%@page import="java.text.SimpleDateFormat"%>
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>
<!doctype html>
<html>
	<head>
		<title>游戏奖励设置</title>
		<base href="<%=basePath%>" />
		<meta charset="utf-8">
		<meta http-equiv="X-UA-Compatible" content="IE=edge">
		<meta name="viewport" content="width=device-width, initial-scale=1">
		<meta name="renderer" content="webkit">
		<meta http-equiv="Cache-Control" content="no-siteapp" />
		<link rel="icon" type="image/png" href="i/buyu.ico">
		<link rel="stylesheet" href="layui/css/layui.css">
		<style>
		h1 {
		    text-align : center;
		    color : red;
		}
		</style>
	</head>

	<body>
	    <h1>金币排行榜奖励</h1> 
	    <form class="layui-form">
			<div class="layui-form-item">
			    <label class="layui-form-label">第一名奖励</label>
			    <div class="layui-input-inline">
				  <select name="firstGoods1" id="firstGoods1"
					    lay-filter="firstGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="firstNumber1" id="firstNumber1"  autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="firstGoods2" id="firstGoods2"
					    lay-filter="firstGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="firstNumber2" id="firstNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
		
            <div class="layui-form-item">
			    <label class="layui-form-label">第二名奖励</label>
			    <div class="layui-input-inline">
				  <select name="secondGoods1" id="secondGoods1"
					    lay-filter="secondGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="secondNumber1" id="secondNumber1" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="secondGoods2" id="secondGoods2"
					    lay-filter="secondGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="secondNumber2" id="secondNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">第三名奖励</label>
			    <div class="layui-input-inline">
				  <select name="thirdGoods1" id="thirdGoods1"
					    lay-filter="thirdGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="thirdNumber1" id="thirdNumber1" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="thirdGoods2" id="thirdGoods2"
					    lay-filter="thirdGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="thirdNumber2" id="thirdNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			
		   <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="go" id="go">确认修改</button>
		     
		   </div>
		 </div>
        </form>
        
        <h1>弹头排行榜奖励</h1> 
	    <form class="layui-form">
			<div class="layui-form-item">
			    <label class="layui-form-label">第一名奖励</label>
			    <div class="layui-input-inline">
				  <select name="WarheadfirstGoods1" id="WarheadfirstGoods1"
					    lay-filter="WarheadfirstGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadfirstNumber1" id="WarheadfirstNumber1" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="WarheadfirstGoods2" id="WarheadfirstGoods2"
					    lay-filter="WarheadfirstGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadfirstNumber2" id="WarheadfirstNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
		
            <div class="layui-form-item">
			    <label class="layui-form-label">第二名奖励</label>
			    <div class="layui-input-inline">
				  <select name="WarheadsecondGoods1" id="WarheadsecondGoods1"
					    lay-filter="WarheadsecondGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadsecondNumber1" id="WarheadsecondNumber1" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="WarheadsecondGoods2" id="WarheadsecondGoods2"
					    lay-filter="WarheadsecondGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadsecondNumber2" id="WarheadsecondNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label">第三名奖励</label>
			    <div class="layui-input-inline">
				  <select name="WarheadthirdGoods1" id="WarheadthirdGoods1"
					    lay-filter="WarheadthirdGoods1">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadthirdNumber1" id="WarheadthirdNumber1" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			<div class="layui-form-item">
			    <label class="layui-form-label"></label>
			    <div class="layui-input-inline">
				  <select name="WarheadthirdGoods2" id="WarheadthirdGoods2"
					    lay-filter="thirdGoods2">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WarheadthirdNumber2" id="WarheadthirdNumber2" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
			
		   <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="Warheadgo" id="Warheadgo">确认修改</button>
		     
		   </div>
		 </div>
        </form>
        
        <h1>周排行榜奖励</h1> 
	    <form class="layui-form">
			<div class="layui-form-item">
			    <label class="layui-form-label">奖励</label>
			    <div class="layui-input-inline">
				  <select name="WeeklyReword" id="WeeklyReword"
					    lay-filter="WeeklyReword">
					<option value=""></option>
				  </select>
				</div>
				<div class="layui-inline">
				   <label class="layui-form-label">数量</label>
				   <div class="layui-input-inline">
				     <input type="number" name="WeeklyRewordNumber" id="WeeklyRewordNumber" autocomplete="off" class="layui-input" min="0">
				   </div>
				 </div>
			</div>
		   <div class="layui-form-item">
		   <div class="layui-input-block">
		     <button type="submit" class="layui-btn" lay-submit="" lay-filter="WeeklyRewordgo" id="WeeklyRewordgo">确认修改</button>
		     
		   </div>
		 </div>
        </form>
	    
		<script src="js/jquery.min.js"></script>
		<script src="layui/layui.js"></script>
        <script>
	       layui.config({
	           base:'layui/dist/'
	       }).extend({
	           formSelects:'formSelects-v4'
	       });
        
           layui.use(['layer','form'], function () {
               var layer = layui.layer, 
                   form = layui.form;
               
               $(function(){
      			   $("select").empty();//清空select
            	   //读取当前游戏奖励配置
            	   $.ajax({
      					type : 'post',
      					url : 'game/RewordRead',
      					async : true,
      					success : function(data) {
      						data = jQuery.parseJSON(data);//json对象
      						if (data.hasOwnProperty("Number1first")) {
	      						$("#firstGoods1").append("<option value=" + data.Number1first.Name +">" + data.Number1first.Name + "</option>");
	      						$("#firstNumber1").val(data.Number1first.ItemCount);
      						}
      						if (data.hasOwnProperty("Number1Second")) {
	      						$("#firstGoods2").append("<option value=" + data.Number1Second.Name +">" + data.Number1Second.Name + "</option>");
	      						$("#firstNumber2").val(data.Number1Second.ItemCount);
      						}
      						if (data.hasOwnProperty("Number2first")) {
	      						$("#secondGoods1").append("<option value=" + data.Number2first.Name +">" + data.Number2first.Name + "</option>");
	      						$("#secondNumber1").val(data.Number2first.ItemCount);
      						}
      						if (data.hasOwnProperty("Number2Second")) {
	      						$("#secondGoods2").append("<option value=" + data.Number2Second.Name +">" + data.Number2Second.Name + "</option>");
	      						$("#secondNumber2").val(data.Number2Second.ItemCount);
      						}
      						if (data.hasOwnProperty("Number3first"))  {
	      						$("#thirdGoods1").append("<option value=" + data.Number3first.Name +">" + data.Number3first.Name + "</option>");
	      						$("#thirdNumber1").val(data.Number3first.ItemCount);
      						}
      						if (data.hasOwnProperty("Number3Second")) {
	      						$("#thirdGoods2").append("<option value=" + data.Number3Second.Name +">" + data.Number3Second.Name + "</option>");
	      						$("#thirdNumber2").val(data.Number3Second.ItemCount);
      						}
      						form.render('select');
      					}
      				}).done(function(){
      					$.ajax({
      	   					type : 'post',
      	   					url : 'game/WarheadRead',
      	   					async : true,
      	   					success : function(data) {
      	   						data = jQuery.parseJSON(data);//json对象
      	  						if (data.hasOwnProperty("WarheadNumber1first")) {
      	      						$("#WarheadfirstGoods1").append("<option value=" + data.WarheadNumber1first.Name +">" + data.WarheadNumber1first.Name + "</option>");
      	      						$("#WarheadfirstNumber1").val(data.WarheadNumber1first.ItemCount);
      	  						}
      	  						if (data.hasOwnProperty("WarheadNumber1Second")) {
      	      						$("#WarheadfirstGoods2").append("<option value=" + data.WarheadNumber1Second.Name +">" + data.WarheadNumber1Second.Name + "</option>");
      	      						$("#WarheadfirstNumber2").val(data.WarheadNumber1Second.ItemCount);
      	  						}
      	  						if (data.hasOwnProperty("WarheadNumber2first")) {
      	      						$("#WarheadsecondGoods1").append("<option value=" + data.WarheadNumber2first.Name +">" + data.WarheadNumber2first.Name + "</option>");
      	      						$("#WarheadsecondNumber1").val(data.WarheadNumber2first.ItemCount);
      	  						}
      	  						if (data.hasOwnProperty("WarheadNumber2Second")) {
      	      						$("#WarheadsecondGoods2").append("<option value=" + data.WarheadNumber2Second.Name +">" + data.WarheadNumber2Second.Name + "</option>");
      	      						$("#WarheadsecondNumber2").val(data.WarheadNumber2Second.ItemCount);
      	  						}
      	  						if (data.hasOwnProperty("WarheadNumber3first"))  {
      	      						$("#WarheadthirdGoods1").append("<option value=" + data.WarheadNumber3first.Name +">" + data.WarheadNumber3first.Name + "</option>");
      	      						$("#WarheadthirdNumber1").val(data.WarheadNumber3first.ItemCount);
      	  						}
      	  						if (data.hasOwnProperty("WarheadNumber3Second")) {
      	      						$("#WarheadthirdGoods2").append("<option value=" + data.WarheadNumber3Second.Name +">" + data.WarheadNumber3Second.Name + "</option>");
      	      						$("#WarheadthirdNumber2").val(data.WarheadNumber3Second.ItemCount);
      	  						}
      	  						form.render('select');
      	   					}
      	   				}).done(function(){
      	   				$.ajax({
      	  					type : 'post',
      	  					url : 'game/getWeeklyrewordConfig',
      	  					async : true,
      	  					success : function(data) {
      	  						data = jQuery.parseJSON(data);//json对象
      	  						if (data.hasOwnProperty("WeeklyNumber1first")) {
      	      						$("#WeeklyReword").append("<option value=" + data.WeeklyNumber1first.Name +">" + data.WeeklyNumber1first.Name + "</option>");
      	      						$("#WeeklyRewordNumber").val(data.WeeklyNumber1first.ItemCount);
      	  						}
      	  						$("select").append("<option value="+">" + "请选择" + "</option>");
      	  						form.render('select');
      	  					}
      	  				}).done(function(){
      	  					$.ajax({
      	  	 					type : 'post',
      	  	 					url : 'pa/Itemload',
      	  	 					async : true,
      	  	 					success : function(data) {
	   		 						data = jQuery.parseJSON(data);//json对象
	   		 						for(var i = 0, l = data.length;i < l;i++){
	   									for(var key in data[i]){
	   										$("#firstGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#firstGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#secondGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#secondGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#thirdGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#thirdGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadfirstGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadfirstGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadsecondGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadsecondGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadthirdGoods1").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WarheadthirdGoods2").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   										$("#WeeklyReword").append("<option value=" + data[i][key] +">" + data[i][key] + "</option>");
	   									}
	   		 						}
	   		 						form.render('select');
      	  	 					}
      	  	 				});
      	  				});
      	   				});
      				});
               });
            
            form.on('submit(go)', function (data) {
            	//对layui data.field循环,转为数组
            	if (data.field.firstGoods1 === "" && data.field.firstGoods2 != "") {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	if (data.field.secondGoods1 === "" && data.field.secondGoods2 != "") {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	if (data.field.thirdGoods1 === "" && data.field.thirdGoods2) {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	var obj = {};
            	var arr = new Array();
            	for (let i in data.field) {
            		if(!data.field[i] == "")
            		  arr.push(data.field[i]);
            	}
            	for(var i = 0;i < arr.length;i++) {
            		obj[arr[i]] = arr[i+1];
            		++i;
            	}
            	$.ajax({
            		type:'post',
            		url:"game/rewordConfig",
            		data:{
            			firstGoods1 : data.field.firstGoods1,
            			firstNumber1 : data.field.firstNumber1,
            			firstGoods2 : data.field.firstGoods2,
            			firstNumber2 : data.field.firstNumber2,
            			secondGoods1 : data.field.secondGoods1,
            			secondNumber1 : data.field.secondNumber1,
            			secondGoods2 : data.field.secondGoods2,
            			secondNumber2 : data.field.secondNumber2,
            			thirdGoods1 : data.field.thirdGoods1,
            			thirdNumber1 : data.field.thirdNumber1,
            			thirdGoods2 : data.field.thirdGoods2,
            			thirdNumber2 : data.field.thirdNumber2
            		},
            		success:function(resp){
	            	    if(resp == "success"){
	            			layer.msg("发布成功",{icon:1});
	            			setTimeout(function(){
	            				window.location.reload();
	            			},1000);
            			}
            		},error:function(){
            			layer.msg("resp",{icon:1});
            		}
            	});
              return false;
            });
            
            form.on('submit(Warheadgo)', function (data) {
            	console.log(data.field);
            	//对layui data.field循环,转为数组
            	if (data.field.WarheadfirstGoods1 === "" && data.field.WarheadfirstGoods2 != "") {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	if (data.field.WarheadsecondGoods1 === "" && data.field.WarheadsecondGoods2 != "") {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	if (data.field.WarheadthirdGoods1 === "" && data.field.WarheadthirdGoods2) {
            		layer.msg("请先选择第一种奖励",{icon:6});
            		return false;
            	}
            	var Warheadobj = {};
            	var Warheadarr = new Array();
            	for (let i in data.field) {
            		if(!data.field[i] == "")
            			Warheadarr.push(data.field[i]);
            	}
            	for(var i = 0;i < Warheadarr.length;i++) {
            		Warheadobj[Warheadarr[i]] = Warheadarr[i+1];
            		++i;
            	}
            	$.ajax({
            		type:'post',
            		url:"game/WarheadrewordConfig",
            		data:{
            			WarheadfirstGoods1 : data.field.WarheadfirstGoods1,
            			WarheadfirstNumber1 : data.field.WarheadfirstNumber1,
            			WarheadfirstGoods2 : data.field.WarheadfirstGoods2,
            			WarheadfirstNumber2 : data.field.WarheadfirstNumber2,
            			WarheadsecondGoods1 : data.field.WarheadsecondGoods1,
            			WarheadsecondNumber1 : data.field.WarheadsecondNumber1,
            			WarheadsecondGoods2 : data.field.WarheadsecondGoods2,
            			WarheadsecondNumber2 : data.field.WarheadsecondNumber2,
            			WarheadthirdGoods1 : data.field.WarheadthirdGoods1,
            			WarheadthirdNumber1 : data.field.WarheadthirdNumber1,
            			WarheadthirdGoods2 : data.field.WarheadthirdGoods2,
            			WarheadthirdNumber2 : data.field.WarheadthirdNumber2
            		},
            		success:function(resp){
	            	    if(resp == "success"){
	            			layer.msg("发布成功",{icon:1});
	            			setTimeout(function(){
	            				window.location.reload();
	            			},1000);
            			}
            		},error:function(){
            			layer.msg("resp",{icon:1});
            		}
            	});
              return false;
            });
            
            form.on('submit(WeeklyRewordgo)', function (data) {
            	$.ajax({
            		type:'post',
            		url:"game/WeeklyrewordConfig",
            		data:{
            			WeeklyReword : data.field.WeeklyReword,
            			WeeklyRewordNumber : data.field.WeeklyRewordNumber
            		},
            		success:function(resp){
	            	    if(resp == "success"){
	            			layer.msg("发布成功",{icon:1});
	            			setTimeout(function(){
	            				window.location.reload();
	            			},1000);
            			}
            		},error:function(){
            			layer.msg("resp",{icon:1});
            		}
            	});
              return false;
            });
          });
        </script>
	</body>

</html>
